package com.douyu.ocean.invoke.task;

import com.douyu.ocean.invoke.PerformanceCollectUtil;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author leiruiqi on 2018/7/30
 */
@Component
public class PerfomanceTask {

    private static Logger log = LoggerFactory.getLogger(PerfomanceTask.class);

    @PostConstruct
    public void init(){
        log.info("PerfomanceTask init");
        PerformanceCollectUtil.init();
    }

    //30秒来一次分析并输出日志
    @Scheduled(fixedRate=30000)
    public void checkPerformance(){
        PerformanceCollectUtil.dataAnalysis();
    }

    @PreDestroy
    public void beforDestroy(){
        log.info("PerfomanceTask PreDestroy");
        PerformanceCollectUtil.dataAnalysis();
    }
}
